package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.MemberDao;
import com.itheima.dao.OrderDao;
import com.itheima.service.ReportService;
import com.itheima.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service(interfaceClass = ReportService.class)
@Transactional
public class ReportServiceImpl implements ReportService {


    @Autowired
    private MemberDao memberDao;

    @Autowired
    private OrderDao orderDao;

    //查询运营数据
    @Override
    public HashMap<String, Object> getBusinessReportData() throws Exception {


        //今天日期
        String today = DateUtils.parseDate2String(DateUtils.getToday());

        //本周日期
        String thisWeekMonday = DateUtils.parseDate2String(DateUtils.getThisWeekMonday());

        //本月第一天
        String firstDay4ThisMonth = DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());


        //今日会员增长数
        Integer todayNewMember=memberDao.findMemberCount(today);
        //总会员数
        Integer totalMember=memberDao.findMemberTotalCount();
        //本周新增会员数
        Integer thisWeekNewMember = memberDao.findMemberCountAfterDate(thisWeekMonday);

        Integer thisMonthNewMember =memberDao.findMemberCountAfterDate(firstDay4ThisMonth);

        //今日预约数
        Integer todayOrderNumber=orderDao.findOderCountByDate(today);

        //本周预约数
        Integer thisWeekOrderNumber= orderDao.findOrderCountAfterDate(thisWeekMonday);

        //本月预约数
        Integer thisMonthOrderNumber = orderDao.findOrderCountAfterDate(firstDay4ThisMonth);

        //今日到诊数
        Integer todayVisitsNumber= orderDao.findVisitsCountByDate(today);


        //本周到诊数
        Integer thisWeekVisitsNumber =orderDao.findVisitsCountAfterDate(today);

        //本月到诊数
        Integer thisMonthVisitsNumber=orderDao.findVisitsCountAfterDate(firstDay4ThisMonth);

        //热门套餐查询
        List<Map> hotSetmeal= orderDao.findHotSetmeal();


        HashMap<String, Object> data =new HashMap<>();
        //报表的日期
        data.put("reportDate", today);
        data.put("todayNewMember",todayNewMember);
        data.put("totalMember",totalMember);
        data.put("thisWeekNewMember",thisWeekNewMember);
        data.put("thisMonthNewMember",thisMonthNewMember);
        data.put("todayOrderNumber",todayOrderNumber);
        data.put("todayVisitsNumber",todayVisitsNumber);
        data.put("thisWeekOrderNumber",thisWeekOrderNumber);
        data.put("thisWeekVisitsNumber",thisWeekVisitsNumber);
        data.put("thisMonthOrderNumber",thisMonthOrderNumber);
        data.put("thisMonthVisitsNumber",thisMonthVisitsNumber);
        data.put("hotSetmeal",hotSetmeal);

        return data;
    }


}
